//
//  BHSportMainHeaderView.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/7/15.
//

import UIKit
protocol BHSportMainHeaderViewDelegate {
    func didSportHeaderSelectTypeBegain(type: Int)
}

class BHSportMainHeaderView: UIView {
    
    var delegate: BHSportMainHeaderViewDelegate?
    
    
    
    static func loadFromXib() -> BHSportMainHeaderView {
        let viewArray = Bundle.main.loadNibNamed("BHSportMainHeaderView", owner: nil, options: nil)
        let view: BHSportMainHeaderView = viewArray![0] as! BHSportMainHeaderView
        return view
    }
    
    @IBAction func actionTypeAct(_ sender: UIButton) {
        self.delegate?.didSportHeaderSelectTypeBegain(type: sender.tag-100)
    }
    
    static var height: CGFloat {
        get {
            return 260
        }
    }

}


class BHSportMainSecView: UIView {
    var didChangeIndexActBlock:((Int) -> Void)?
    
    @IBOutlet weak var waitStartBtn: UIButton!
    @IBOutlet weak var goingBtn: UIButton!
    
    @IBOutlet weak var move_line: UILabel!
    @IBOutlet weak var endBtn: UIButton!
    
    //未开始-85  进行中0  已结束85
    @IBOutlet weak var move_centerX: NSLayoutConstraint!
 
    
    static func loadFromXib() -> BHSportMainSecView {
        let viewArray = Bundle.main.loadNibNamed("BHSportMainHeaderView", owner: nil, options: nil)
        let view: BHSportMainSecView = viewArray![1] as! BHSportMainSecView
        return view
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.move_line.addLayerCorner(2, 0, .white)
    }
    
    @IBAction func changeIndexAct(_ sender: UIButton) {
        if sender.isSelected == true {
            return
        }
        sender.isSelected = true
        if sender == self.waitStartBtn {
            self.move_centerX.constant = -85
            self.goingBtn.isSelected = false
            self.endBtn.isSelected = false
            self.didChangeIndexActBlock?(0)
        }else if sender == self.goingBtn {
            self.move_centerX.constant = 0
            self.waitStartBtn.isSelected = false
            self.endBtn.isSelected = false
            self.didChangeIndexActBlock?(1)
        }else {
            self.waitStartBtn.isSelected = false
            self.goingBtn.isSelected = false
            self.move_centerX.constant = 85
            self.didChangeIndexActBlock?(2)
        }
    }
    
    static var height: CGFloat {
        get {
            return 45
        }
    }

}



class BHSportRecordNavigationBar: UIView {
    var didChangeIndexActBlock:((Int) -> Void)?

    @IBOutlet weak var runRecordBtn: UIButton!
    
    @IBOutlet weak var otherRecordBtn: UIButton!
    
    
    static func loadFromXib() -> BHSportRecordNavigationBar {
        let viewArray = Bundle.main.loadNibNamed("BHSportMainHeaderView", owner: nil, options: nil)
        let view: BHSportRecordNavigationBar = viewArray![2] as! BHSportRecordNavigationBar
        return view
    }
    
    @IBAction func changeIndexAct(_ sender: UIButton) {
        if sender.isSelected == true {
            return
        }
        sender.isSelected = true
        if sender == self.runRecordBtn {
            self.otherRecordBtn.isSelected = false
            self.didChangeIndexActBlock?(0)
        }else {
            self.runRecordBtn.isSelected = false
            self.didChangeIndexActBlock?(1)
        }
    }
    
    @IBAction func back_act(_ sender: Any) {
        self.didChangeIndexActBlock?(-1)

    }
    
}
